package com.xiaojie.service.impl;

import com.xiaojie.entity.user.User;
import com.xiaojie.mapper.UserMapper;
import com.xiaojie.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author yan
 * @Date 2021/5/21 10:01
 * @Version 1.0
 **/
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public List<User> getAll() {
        return userMapper.selectAllUser();
    }

    @Override
    @Transactional(rollbackFor = {Exception.class,RuntimeException.class})
    public Integer saveUser(String name,Integer age) {
    log.info("用户的姓名是:{}",name);
        User user=new User();
        user.setName(name);
        user.setAge(age);
        Integer result = userMapper.addUser(user);
        return result;
    }
}
